FROM tiangolo/uwsgi-nginx:python3.10

# Set working directory
WORKDIR /app

# Copy project files
COPY . /app

RUN cp sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y gcc libc-dev build-essential python3-dev

RUN pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
RUN pip install --upgrade pip

# Install PDM
RUN pip install pdm

# Install dependencies using PDM
RUN pdm config pypi.url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple
RUN pdm install --prod

# Create a non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser

# Change ownership of the app directory
RUN chown -R appuser:appuser /app

# Switch to non-root user (创建 nignx 配置文件需要 root 权限)
# USER appuser

# Expose port
EXPOSE 5000

# Start uWSGI
CMD ["pdm", "run", "uwsgi", "--ini", "uwsgi.ini"]
